<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<script type="text/javascript">
function check() {
document.getElementById('ok').disabled = 'disabled';
}

//返回到企业用户列表
function backcompanyUserlist() {
location.href="<%=request.getContextPath()%>/sso/company_user/list?searchValue=${searchValue}";
}

</script>
<script type="text/javascript">
$(document).ready(function() {
	  // 电话号码验证
	  jQuery.validator.addMethod("isTel", function(value, element) {
	    var tel = /^(\d{3,4}-)?\d{7,8}$/g; // 区号－3、4位 号码－7、8位
	    return this.optional(element) || (tel.test(value));
	  }, "请正确填写您的电话号码。");
	  // 匹配密码，以字母开头，长度在6-12之间，必须包含数字和特殊字符。
	  jQuery.validator.addMethod("isPwd", function(value, element) {
	    var str = value;
	    if (str.length < 6 || str.length > 18)
	      return false;
	    if (!/^[a-zA-Z]/.test(str))
	      return false;
	    if (!/[0-9]/.test(str))
	      return fasle;
	    return this.optional(element) || /[^A-Za-z0-9]/.test(str);
	  }, "以字母开头，长度在6-12之间，必须包含数字和特殊字符。");
	  $("#companyuserform").validate({
	    errorElement : 'span',
	    errorClass : 'help-block',
	    rules : {
	      username : "required",
	      email : {
	        required : true,
	        email : true
	      },
	      password : {
	        required : true,
	        isPwd : true
	      },
	      password1 : {
	        required : true,
	        isPwd : true,
	        equalTo : "#password"
	      },
	      phone : {
	    	required : true,
	        isTel : true
	      }
	    },
	    messages : {
	      firstname : "请输入姓名",
	      email : {
	        required : "请输入Email地址",
	        email : "请输入正确的email地址"
	      },
	      password : {
	        required : "请输入密码",
	        minlength : jQuery.format("密码不能小于{0}个字 符")
	      },
	      password1 : {
	        required : "请输入确认密码",
	        minlength : "确认密码不能小于5个字符",
	        equalTo : "两次输入密码不一致不一致"
	      },
	      phone : {
	        required : "请输入电话号码"
	      }
	    },
	    //自定义错误消息放到哪里
	    errorPlacement : function(error, element) {
	      element.next().remove();//删除显示图标
	      element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
	      element.closest('.control-group').append(error);//显示错误消息提示
	    },
	    //给未通过验证的元素进行处理
	    highlight : function(element) {
	      $(element).closest('.control-group').addClass('has-error has-feedback');
	    },
	    //验证通过的处理
	    success : function(label) {
	      var el=label.closest('.control-group').find("input");
	      el.next().remove();//与errorPlacement相似
	      el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
	      label.closest('.control-group').removeClass('has-error').addClass("has-feedback has-success");
	      label.remove();
	    },
	  });
	});

</script>
</head>
<body class="page-header-fixed page-full-width">
		<div class="page-content">

			<div class="container-fluid">
				<div class="row-fluid">

					<div class="span12">


						<h3 class="page-title">

							<!--系统用户管理 <small>欢迎您，admin!</small> -->

						</h3>

						<ul class="breadcrumb">

							<li><i class="icon-home"></i> <a href="index.html">Home</a>

								<i class="icon-angle-right"></i></li>

							<li><a href="#">单点登录系统</a> <i class="icon-angle-right"></i>

							</li>

							<li><a href="#">企业用户</a></li>

						</ul>



					</div>

				</div>

				<div class="portlet-body form">

					<c:if test="${success==false}">
						<div class="alert alert-failure">
							<button class="close" data-dismiss="alert"></button>
							<strong><spring:message code="failure"></spring:message>!</strong>
							${errorMsg}
						</div>
					</c:if>
					<c:if test="${success }">
						<div class="alert alert-success">
							<button class="close" data-dismiss="alert"></button>
							<strong><spring:message code="success"></spring:message>!</strong>
							<spring:message code="save success"></spring:message>
							!
						</div>
					</c:if>
                      <c:if test="${success==false}">
						<div class="alert alert-failure">
									<button class="close" data-dismiss="alert"></button>
									<strong><spring:message code="failure"></spring:message>!</strong> ${passwprdmsg}
						</div>
					</c:if>
					<h3 class="page-title">
						<c:if test="${oauthUser.oauthUserId==null }">
							新增企业用户
						</c:if>
						<c:if test="${oauthUser.oauthUserId!=null }">
							编辑企业用户
						</c:if>
					</h3>


					<form role="form"
						action="<c:if test="${oauthUser.oauthUserId==null}">insert</c:if>
				    <c:if test="${oauthUser.oauthUserId!=null}">edit</c:if>"
						method="post" class="form-horizontal" id="companyuserform">
						<input type="hidden" name="searchValue" value="${searchValue}" /><!-- company_code -->
						<input type="hidden" name="cList" value="${company_list}" /><!-- company company_code -->
						<input type="hidden" name="id"
							value="${oauthUser.oauthUserId}"></input> <input
							type="hidden" name="token" value="${token}"></input>
                      
						<div class="control-group">
							<label class="control-label" for="username">用户名：</label>
							<div class="controls">
								<input type="text" maxLength="200"
									<c:if test="${oauthUser.oauthUserId!=null}">disabled="disabled"</c:if> id="username"
									name="username" value="${oauthUser.username }"
									class="m-wrap"/>
								<c:if test="${oauthUser.oauthUserId!=null}">
									<input type="hidden" name="username"
										value="${oauthUser.username }"></input>
								</c:if>

								<span class="help-inline"></span>

							</div>

						</div>
						
						
						<c:if test="${oauthUser.oauthUserId==null}">
								<div class="control-group">

								<label class="control-label" for="password"><spring:message code="user password"></spring:message>：</label>

								<div class="controls">

									<input maxlength="200" name="password" type="password" id="password" class="m-wrap" />

									<span class="help-inline"></span>

								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label" for="password1"><spring:message code="confirm password"></spring:message>：</label>

								<div class="controls">

									<input type="password" name="password1" id="password1" maxlength="200" class="m-wrap" />

									<span class="help-inline"></span>

								</div>
							</div>
							</c:if>

						<div class="control-group">
							<label class="control-label" for="email">邮箱：</label>
							<div class="controls">

								<input type="text" maxlength="200" name="email" id="email"
									value="${oauthUser.email}" class="m-wrap"/>
								<span class="help-inline"></span>

							</div>

						</div>

						<div class="control-group">
							<label class="control-label" for="phone">电话：</label>
							<div class="controls">

								<input type="text" maxlength="200" name="phone" id="phone"
									value="${oauthUser.phone}" class="m-wrap"/>
								<span class="help-inline"></span>

							</div>

						</div>

						<div class="control-group">
							<label class="control-label">企业编号:</label>
							<div class="controls">
								<select tabindex="1" data-placeholder="Choose a companyCode"
									class="span2 m-wrap" name="companyCode">
									<option value=""></option>
									<c:forEach var="company" items="${company_list}">
										<option
											<c:if test="${searchValue==company.companyCode}">selected="selected"</c:if>
											value="${company.companyCode}">${company.companyCode}</option>
									</c:forEach>
								</select>
							</div>
						</div>


						<div class="form-actions">
							<button type="submit" id="ok" class="btn blue">
								<spring:message code="btn.common.save"></spring:message>
							</button>
							<button type="button" onclick="backcompanyUserlist();"
								class="btn">
								<spring:message code="btn.common.back"></spring:message>
							</button>

						</div>

					</form>

				</div>

		<form id="backForm" action="<%=request.getContextPath()%>/sso/company_user/list" method="post">
			<input type="hidden" name="searchValue" value="${searchValue}"/>
		</form>
		
			</div>
		</div>



</body>
</html>